<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=0, viewport-fit=cover" />
	<title>apply</title>
</head>
<body>
<script>
var fn = function (num1, num2) {
	console.log(this);
	return num1 + num2
}

Function.prototype._apply = function (ctx, aParams) {
	if (typeof ctx !== 'object') throw new Error('您传进一的实参 ctx 不是一个对象')
	ctx = ctx || window;
	if (typeof this !== 'function') throw new Error('调用者不一个方法')

	ctx.fn = this;
	const result = ctx.fn(...aParams);
	delete ctx.fn;
	return result;
};

console.log(
	fn._apply({ name: 'wgm' }, [1, 2])
)

</script>
</body>
</html>
